import java.util.Stack;

public class test_24_09_06 {
    class Solution01 {
        public int[] dailyTemperatures(int[] temperatures) {
            // 使用单调栈
            Stack<Integer> stack = new Stack<>();
            int len = temperatures.length;
            int temperature = 0;
            int[] answer = new int[len];
            for (int i = 0; i < len; i++) {
                temperature = temperatures[i];
                while (!stack.isEmpty() && temperature > temperatures[stack.peek()]) {
                    int index = stack.pop();
                    answer[index] = i - index;
                }
                stack.push(i);
            }
            return answer;
        }
    }

    class Solution02 {
        public int numIslands(char[][] grid) {
            int Island = 0;
            for (int i = 0; i < grid.length; i++) {
                for (int j = 0; j < grid[0].length; j++) {
                    if (grid[i][j] == '1') {
                        dfs(grid, i, j);
                        Island++;
                    }
                }
            }
            return Island;
        }

        public void dfs(char[][] grid, int i, int j) {
            //超出网格范围
            if (i < 0 || j < 0 || i >= grid.length || j >= grid[0].length || grid[i][j] == '0')
                return;
            if (grid[i][j] != '1')
                return;
            //避免重复
            //1. 陆地(未遍历)
            //2. 陆地(已遍历)
            //0. 海洋
            grid[i][j] = '2';
            dfs(grid, i - 1, j);
            dfs(grid, i + 1, j);
            dfs(grid, i, j - 1);
            dfs(grid, i, j + 1);
        }
    }


    //字符串解码


    public static String[] splitBracketString(String str) {
        // 使用正则表达式匹配数字后面跟着方括号内的内容
        String regex = "(\\d+)\\[(.*?)\\]";
        // 替换操作：将匹配的数字和方括号内的内容替换为数字后面跟空格和方括号内的内容
        String replacement = "$1 $2";
        String processedString = str.replaceAll(regex, replacement);

        // 使用空格分割字符串
        return processedString.split("\\s+");
    }

    public static void main(String[] args) {
        String s = "1s3 PSt";
        String result = s.replaceAll("[\\s\\d]+", "");
        System.out.println(result);
    }

    class Solution03 {
        public int romanToInt(String s) {
            s = s.replace("IV", "a");
            s = s.replace("IX", "b");
            s = s.replace("XL", "c");
            s = s.replace("XC", "d");
            s = s.replace("CD", "e");
            s = s.replace("CM", "f");

            int res = 0;
            for (int i = 0; i < s.length(); i++) {
                res += getValue(s.charAt(i));
            }
            return res;
        }

        public int getValue(char c) {
            switch (c) {
                case 'I':
                    return 1;
                case 'V':
                    return 5;
                case 'X':
                    return 10;
                case 'L':
                    return 50;
                case 'C':
                    return 100;
                case 'D':
                    return 500;
                case 'M':
                    return 1000;
                case 'a':
                    return 4;
                case 'b':
                    return 9;
                case 'c':
                    return 40;
                case 'd':
                    return 90;
                case 'e':
                    return 400;
                case 'f':
                    return 900;
            }
            return 0;
        }
    }
    //int a = Integer.MAX_VALUE




}
